﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Common;
using ZHDJ.Data.Models.MassLine;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal
{
    public partial class MassLineIndex : PortalPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            DataTable dt = PartyPhotoWallImage.GetBranchPhotoWallList(10, "", "MassLine");
            this.rptHonorHall.DataSource = dt;
            this.rptHonorHall.DataBind();
            //上级精神
            this.rpSuperiorSpirit.DataSource = PartyArticle.GetArticleTitle("MassLine", "SuperiorsSpirit", "limit 0,6",getCreateTime:true).Tables[0];
            this.rpSuperiorSpirit.DataBind();
            //民情日记
            this.rpMinQingRiJi.DataSource = PartyArticle.GetArticleTitle("MassLine", "mqrj", "limit 0,6", getCreateTime: true).Tables[0];
            this.rpMinQingRiJi.DataBind();

            //学习心得
            this.rpXueXiXinDe.DataSource = PartyArticle.GetArticleTitle("MassLine", "xxxd", "limit 0,6", getCreateTime: true).Tables[0];
            this.rpXueXiXinDe.DataBind();

            //活动简报
            this.rpActivityBulletin.DataSource = PartyArticle.GetArticleTitle("MassLine", "ActivityBulletin", "limit 0,6", getCreateTime: true).Tables[0];
            this.rpActivityBulletin.DataBind();

            //活动动态
            this.rpActivityDynamic.DataSource = PartyActivityDynamic.GetrpHuoDongDongTai(0, 6, " IsImportant=0");
            this.rpActivityDynamic.DataBind();

            //要闻
            this.rptItemsIsImportant.DataSource = PartyActivityDynamic.GetrpHuoDongDongTai(0, 6, " IsImportant=1");
            this.rptItemsIsImportant.DataBind();

            //先进典型
            this.rptMassHonour.DataSource = PartyArticle.GetMassHonourArticle(0, 20, "4");
            this.rptMassHonour.DataBind();

            this.rpActivityPublic.DataSource = PartyBranchDraft.GetPartyBranchDraft(0, 6, "", "", "");
            this.rpActivityPublic.DataBind();
        }

        /// <summary>
        /// 截取标题
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string CutLongTitle(object obj, int length)
        {
            string title = Convert.ToString(obj);
            if (title.Length > length)
            {
                title = title.Substring(0, length) + "...";
            }
            return title;
        }

        public string GetTitle()
        {
            string Title = "";
            DataTable dt = PartyActivityDynamic.GetrpHuoDongDongTai(0, 1, " IsFirst=1");
            if (dt.Rows.Count > 0)
            {
                Title = Convert.ToString(dt.Rows[0]["Title"]);
            }
            return Title;
        }

        public string GetContent()
        {
            string Content = "";
            DataTable dt = PartyActivityDynamic.GetrpHuoDongDongTai(0, 1, "IsFirst=1");
            if (dt.Rows.Count > 0)
            {
                Content = Convert.ToString(dt.Rows[0]["Content"]);
                Content = ZHDJ.WebPage.PortalUtil.GetHtmlText(Content).Trim();
                Content = Content.Trim();
            }
            return Content;
        }
    }
}